Page({
  data: {
    texVal: '',
    serviceStar: 0,
    reasonablePriceStar: 0,
    companyReputationStar: 0,
    supportStar: 0,
    safetyAndStar: 0,
    convenienceStar: 0,
    dialogShow: false,
    uploadList: []

  },
  bindIAreaInput (e) {
    this.setData({ texVal: e.detail.value })
  },
  starOnChange (e) {
    this.setData({ [e.currentTarget.dataset.code]: e.detail })
  },
  uploadMulti () {
    let that = this;
    let conut = 9 - that.data.uploadList.length;
    wx.chooseMedia({
      count: conut,
      mediaType: ['mix'],
      sourceType: ['album'],
      success (res) {
        let list = that.data.uploadList;
        if (res.tempFiles.length) {
          res.tempFiles.forEach(element => {
            list.push({
              tempFilePath: element.tempFilePath,
              fileType: element.fileType
            })
          });
        }
        that.setData({ uploadList: list });
      }
    })
  },
  delUploadList (e) {
    let index = e.currentTarget.dataset.index;
    let list = this.data.uploadList;
    list.splice(index, 1);
    this.setData({ uploadList: list });
  },
  showMulitMdedia (e) {
    let list = [];
    this.data.uploadList.forEach(element => {
      list.push({
        url: element.tempFilePath,
        type: element.fileType
      })
    })
    let index = e.currentTarget.dataset.index;
    wx.previewMedia({
      sources: list,
      current: index
    })
  },
  async submit () {
    if (this.data.texVal.length == 0) {
      return wx.showToast({ title: '请输入您输入使用评论', icon: 'none', duration: 1500, });
    }
    if (this.data.reasonablePriceStar == 0) {
      return wx.showToast({ title: '请选择【价格合理性】的星级', icon: 'none', duration: 1500, });
    }
    if (this.data.companyReputationStar == 0) {
      return wx.showToast({ title: '请选择【公司信誉】的星级', icon: 'none', duration: 1500, });
    }
    if (this.data.supportStar == 0) {
      return wx.showToast({ title: '请选择【客户支持】的星级', icon: 'none', duration: 1500, });
    }
    if (this.data.safetyAndStar == 0) {
      return wx.showToast({ title: '请选择【安全性和环保性】的星级', icon: 'none', duration: 1500, });
    }
    if (this.data.convenienceStar == 0) {
      return wx.showToast({ title: '请选择【便捷性】的星级', icon: 'none', duration: 1500, });
    }
    let uploadList = [];
    if (this.data.uploadList.length > 0) {
      for (const item of this.data.uploadList) {
        let uploadUrl = await wx.$uploadReq(item.tempFilePath);
        if (uploadUrl.response.errcode != 0) return wx.$toast(res.response.errmsg)
        if (uploadUrl.data.row && uploadUrl.data.row.length > 0) {
          uploadList.push(uploadUrl.data.row[0].data)
        } else {
          return wx.$toast('上传进场图片失败,请重新再试')
        }
      }
    }
    console.log(uploadList, '查看一下咯？')
  }
})